package com.smart.builder.xml;

import java.util.List;

import com.smart.hotelsmart.BillingAddressType;
import com.smart.hotelsmart.BookRoomType;
import com.smart.hotelsmart.InfoBookHotelResponseType;
import com.smart.hotelsmart.InfoHotelResponseType;
import com.smart.hotelsmart.ListBookRoomType;
import com.smart.hotelsmart.PaymentType;
import com.smart.persistence.entity.BillingAddress;
import com.smart.persistence.entity.BookHotel;
import com.smart.persistence.entity.BookRoom;
import com.smart.persistence.entity.Payment;
import com.smart.service.util.UtilDate;

public class BuilderInfoBookHotelResponseType {
	
	 /*/# INICIO - EXERC. 2*/
	public InfoBookHotelResponseType createInfoBookHotelResponseType(BookHotel book){
		assert book != null : "book = null";
		InfoBookHotelResponseType response = new InfoBookHotelResponseType();
		BuilderInfoHotelResponseType builder = new BuilderInfoHotelResponseType();
		InfoHotelResponseType infoHotel = builder.generateInfoHotelResponseFromEntity(book.getHotel(), book.getCheckIn(), book.getCheckOut());
		assert infoHotel != null : "InfoHotelResponseType = null p/" + book.getHotel().getId();
		response.setHotel(infoHotel);
		response.setPayment(createPaymentType(book.getPayment()));
		response.setListBookRoom(createListBookRoom(book.getBooksRoom()));
		response.setBillingAddress(createBillingAddressType(book.getPayment().getAdress()));
		
		response.setArrival(UtilDate.createGregorianCalendar(book.getCheckIn()));
		response.setDeparture(UtilDate.createGregorianCalendar(book.getCheckOut()));
		
		
		return response;
	}
	// FIM - EXERC. 2 #*/
	
	 /*/# INICIO - EXERC. 2	*/
	private ListBookRoomType createListBookRoom(List<BookRoom> quartos){
		assert quartos != null : "List<BookRoom> == null";
		assert !quartos.isEmpty() : "List<BookRoom> is Empty";
		ListBookRoomType listBookRoomType = new ListBookRoomType();
		for (BookRoom bookRoom : quartos) {
			BookRoomType bookRoomType = createBookRoomType(bookRoom);
			listBookRoomType.getBookRoom().add(bookRoomType);
		}
		return listBookRoomType;
	}
	// FIM - EXERC. 2 #*/

	 /*/# INICIO - EXERC. 2	*/
	private BookRoomType createBookRoomType(
			BookRoom bookRoom) {
		assert bookRoom != null : " bookRoom == null";
		BookRoomType bookRoomType = new BookRoomType();
		bookRoomType.setAmountAdults(bookRoom.getAmountAdults());
		bookRoomType.setAmountChildren(bookRoom.getAmountchildren());
		assert bookRoom.getRoom() != null : "bookRoom.getRoom == null";
		assert bookRoom.getRoom().getRoomType().getCodRoom() != 0;
		bookRoomType.setFirstNameHost(bookRoom.getHostFirstName());
		bookRoomType.setLastNameHost(bookRoom.getHostLastName());
		bookRoomType.setCodeRoom(bookRoom.getRoom().getRoomType().getCodRoom());
		return bookRoomType;
	}
	// FIM - EXERC. 2 #*/

	
	 /*/# INICIO - EXERC. 2	*/
	private BillingAddressType createBillingAddressType(BillingAddress billingAddress){
		assert billingAddress != null : "billingAddress = null";
		BillingAddressType billingAddressType = new BillingAddressType();
		billingAddress.setCity(billingAddress.getCity());
		billingAddress.setCountry(billingAddress.getCountry());
		billingAddress.setState(billingAddress.getState());
		billingAddress.setStreetAddress(billingAddress.getStreetAddress());
		billingAddress.setZipCode(billingAddress.getZipCode());
		return billingAddressType;
		
	}
	// FIM - EXERC. 2 #*/
	
	/*/# INICIO - EXERC. 2 	*/
	private PaymentType createPaymentType(Payment payment){
		PaymentType paymentType = new PaymentType();
		// FIM - EXERC. 2 #*/
		//INICIO EXER. 6
		
		if(payment != null && payment.getCard() != null ){
			
			assert payment != null : "payment = null";
			paymentType.setTotal (payment.getTotal());
			assert payment.getCard() != null : "payment card = null";
			paymentType.setCardNumber(payment.getCard().getCardNumber());
			paymentType.setCardType(payment.getCard().getCardType());
			paymentType.setExpiryMonth(payment.getCard().getExpiryMonth());
			paymentType.setExpiryYear(payment.getCard().getExpiryYear());
			paymentType.setFirstName(payment.getCard().getFirstName());
			paymentType.setLastName(payment.getCard().getLastName());
			paymentType.setSecurityCode(payment.getCard().getSecurityCode());
		
		}
		// FIM - EXERC. 6 #/
		/*/# INICIO - EXERC. 2*/
		return paymentType;
		
	}
	// FIM - EXERC. 2 #*/

	 
	
	

}
